package org.example.exception;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 李云龙
 * @program: shiro_login
 * @description: 权限异常类 @ControllerAdvice注解用于定义一个全局的异常处理类，而@ExceptionHandler注解则用于指定处理特定异常的方法
 * @date 2024-10-17 22:28:38
 */
@ControllerAdvice("org.example.controller")
public class PermissionsException {
    @ResponseBody
    @ExceptionHandler(UnauthorizedException.class)
    public String unauthorizedException(Exception e) {
        return "无权限";
    }

    @ResponseBody
    @ExceptionHandler(AuthorizationException.class)
    public String authorizationException(Exception e) {
        return "权限认证失败";
    }
}
